//
//  QSWorkStationViewController.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/5/13.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSWorkStationViewController.h"
#import "QSWorkStationDataViewController.h"
#import "QSWorkStationInterface.h"
@interface QSWorkStationViewController ()<VTMagicViewDataSource, VTMagicViewDelegate>
@property (nonatomic, strong)  NSArray *menuList;
@end

@implementation QSWorkStationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"工作台";
    [self configSubView];
    
    [self checkiSJingXin];//请求权限  不是经信不可看全部
    
   
}

- (void)checkiSJingXin{
    [QSWorkStationInterface getAllWorkListWithPageIndex:1 andBlock:^(ResponseMessage *rspStatusAndMessage, QSWorkStationDataModel *resultModel) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            [self generateTestDataWithIsJingXin:resultModel.isJingXin isEnterprisePerson:resultModel.isEnterprisePerson];
            [self.magicController.magicView reloadData];
        }
    }];
}

- (void)configSubView{
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F1F3F4"];
    [self addChildViewController:self.magicController];
    [self.view addSubview:self.magicController.view];
}

#pragma mark - 懒加载
- (VTMagicController *)magicController {
    if (!_magicController) {
        _magicController = [[VTMagicController alloc] init];
        _magicController.view.translatesAutoresizingMaskIntoConstraints = NO;
        _magicController.magicView.navigationColor = [UIColor QSColorWhiteFFFFFF];
        _magicController.magicView.sliderColor = [UIColor colorWithHexString:@"#28A6FF"];
        _magicController.magicView.switchStyle = VTSwitchStyleDefault;
        _magicController.magicView.layoutStyle = VTLayoutStyleDivide;
        _magicController.magicView.sliderWidth = kRealValue(44);
        _magicController.magicView.separatorColor = [UIColor colorWithHexString:@"dddddd"];
        _magicController.magicView.navigationHeight = 44.f;
        _magicController.magicView.againstStatusBar = NO;
        _magicController.magicView.sliderExtension = 10.0;
        _magicController.magicView.dataSource = self;
        _magicController.magicView.delegate = self;
        _magicController.magicView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNavgationBarHeight - kTabBarHeight);

    }
    return _magicController;
}

#pragma mark - VTMagicViewDataSource
- (NSArray<NSString *> *)menuTitlesForMagicView:(VTMagicView *)magicView {
    return _menuList;
}
    
- (UIButton *)magicView:(VTMagicView *)magicView menuItemAtIndex:(NSUInteger)itemIndex {
    static NSString *itemIdentifier = @"itemIdentifier";
    UIButton *menuItem = [magicView dequeueReusableItemWithIdentifier:itemIdentifier];
    if (!menuItem) {
        menuItem = [UIButton buttonWithType:UIButtonTypeCustom];
        [menuItem setTitleColor:[UIColor colorWithHexString:@"666666"] forState:UIControlStateNormal];
        [menuItem setTitleColor:[UIColor colorWithHexString:@"#128BEC"] forState:UIControlStateSelected];
        menuItem.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:14.f];
    }
    return menuItem;
}
    
- (UIViewController *)magicView:(VTMagicView *)magicView viewControllerAtPage:(NSUInteger)pageIndex {
    
    QSWorkStationDataViewController *dataVc = [[QSWorkStationDataViewController alloc] init];
    dataVc.index = pageIndex;
    dataVc.titleStr = [self.menuList objectAtIndex:pageIndex];
    return dataVc;
}
#pragma mark - functional methods
- (void)generateTestDataWithIsJingXin:(BOOL)isJingXin
                   isEnterprisePerson:(BOOL)isEnterprisePerson{
    if (isJingXin) {
        _menuList = @[@"全部", @"我的"];
//        _magicController.magicView.navigationHeight = 0;
//        _magicController.magicView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNavgationBarHeight - kTabBarHeight);
//        self.magicController.magicView.navigationView.hidden = YES;

    }else{
        _menuList = @[@"我的"];
//        _magicController.magicView.navigationHeight = 0.f;
//        _magicController.magicView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNavgationBarHeight - kTabBarHeight);
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
